#!/bin/bash

# Copyright 2021 PerfKitBenchmarker Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:/bin/java::")
export SPARK_SSH_OPTS="-o IdentitiesOnly=yes \
  -o StrictHostKeyChecking=no \
  -o UserKnownHostsFile=/dev/null \
  -o IdentityFile={{ spark_private_key }} \
  -o BatchMode=yes"

# Spark has sane defaults for these, but set them explicitly incase we do
# anything weird with machine_type. See
# https://spark.apache.org/docs/latest/spark-standalone.html#cluster-launch-scripts
export SPARK_WORKER_MEMORY={{ worker_memory_mb }}m
export SPARK_WORKER_CORES={{ worker_vcpus }}
# Otherwise Spark uses tiny boot disk.
export SPARK_WORKER_DIR={{ scratch_dir }}
export SPARK_LOCAL_DIRS={{ scratch_dir }}
# Add Hadoop jars to Spark
# https://spark.apache.org/docs/latest/hadoop-provided.html
export SPARK_DIST_CLASSPATH="$({{ hadoop_cmd }} classpath)"
export PYSPARK_PYTHON={{ python_cmd }}
